{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "\n",
    "imgurl = 'http://image.angelimg.spbeen.com/00000mx00000/PwlOdwrCvFb1J5Yl8dXs274211/q0rMFfPukJOrh3AIygMQ274211-xhpOvA.jpg'\n",
    "headers = {'Referer':'http://angelimg.spbeen.com/', 'User-Agent': 'python-requests/2.22.0'}\n",
    "\n",
    "resp2 = requests.get(imgurl, headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [404]>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resp2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<Error>\\n  <Code>NoSuchKey</Code>\\n  <Message>The specified key does not exist.</Message>\\n  <RequestId>5F277C835B2D1C333981C8A5</RequestId>\\n  <HostId>image.angelimg.spbeen.com</HostId>\\n  <Key>00000ux00000//2HjZaU3pV6uv35bjm0F653021/o5DocNyloCTjB43npeN753021-12soMTi.jpg</Key>\\n</Error>\\n'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resp2.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 通过字节来保存图片，而不能使用字符串\n",
    "with open('demo.jpg', 'wb') as file:\n",
    "    file.write(resp2.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
